package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.OP_NoticeFile;
import com.ymttest.database.model.OP_NoticeInfo;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name :DefaultWapper.java
 * @Author : zhouyi
 * @Date : 2015年6月1日
 * @Copyright : 洋码头
 ************************************************************************************/
public class YmtCsWapper {
	SqlManager manage;

	public YmtCsWapper() {
		if (manage == null || manage.getEnv() != "ymt" + EnvSetup.getEnv() || manage.isClosed()) {
			manage = new SqlManager("ymtcs");
		}
	}

	/**
	 * 使用 accountid 查询信息
	 * 
	 * @param accountid
	 * @return {dCreateTime=2016-01-26 10:33:57.263, dUpdateTime=2016-01-26
	 *         10:33:57.263, fAvailAmount=0.00, iAction=0, iCurrencyType=1,
	 *         iUserId=20000000, iAccountType=0, Version=0, fRewardAmount=0.00,
	 *         fFreezeAmount=0.00, sAccountInfoId=00010020000000, sMemo=自动化测试专用}
	 * @throws InterruptedException
	 */
	public List<OP_NoticeInfo> selectAllNoticeInfo() throws InterruptedException {
		@SuppressWarnings("unchecked")
		List<OP_NoticeInfo> pia = manage.getSelectResults("com.ymttest.database.mapping.YmtCsMapper.selectAllNoticeInfo", null);
		manage.commit();
		return pia;
	}
	public List<OP_NoticeInfo> selectNoticeInfoByNoticeid(String noticeid) throws InterruptedException {
		Map m=new HashMap<>();
		m.put("noticeid", noticeid);
		@SuppressWarnings("unchecked")
		List<OP_NoticeInfo> pia = manage.getSelectResults("com.ymttest.database.mapping.YmtCsMapper.selectNoticeInfoByNoticeid", m);
		manage.commit();
		return pia;
	}
	public List<OP_NoticeFile> selectNoticeFileByNoticeid(String noticeid) throws InterruptedException {
		Map m=new HashMap<>();
		m.put("noticeid", noticeid);
		@SuppressWarnings("unchecked")
		List<OP_NoticeFile> pia = manage.getSelectResults("com.ymttest.database.mapping.YmtCsMapper.selectNoticeFileByNoticeid", m);
		manage.commit();
		return pia;
	}
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		try {
			
			Map m = new HashMap();
			m.put("UserId", "21000002");
			m.put("BeginTime", "2016-01-28 18:05:26.237");
			m.put("EndTime", "2016-01-29 22:05:26.237");
			m.put("AccountingType", 1);

			m.put("limit", 20);
			/*
			 * List<HashMap> rm=new
			 * AccountDefaultWapper().selectAccountEntryByMap(m);
			 */

			List<OP_NoticeInfo> rm = new YmtCsWapper().selectAllNoticeInfo();

//			Logger.debug("msize:" + rm.size());
			 Logger.debug("m:"+FormatUtil.beanToGSONString(rm));
			 for (OP_NoticeInfo op_NoticeInfo : rm) {
				 Logger.debug( FormatUtil.beanToGSONString(new YmtCsWapper().selectNoticeInfoByNoticeid(op_NoticeInfo.getNoticeId())));
				 
				 Logger.debug( FormatUtil.beanToGSONString(new YmtCsWapper().selectNoticeFileByNoticeid(op_NoticeInfo.getNoticeId())));
			}
			
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
